﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dukou.Dao.Implement;
using Dukou.Example.Core.Domain;
using Dukou.Example.Core.QueryDomain;
using NHibernate;
using Dapper;
using System.Data;

namespace Dukou.Example.Core.Dao.Impl
{
    public class UserDao : NHibernateDao<User, long>, IUserDao
    {
        public IList<UserQuery> Query()
        {
            return this.HibernateTemplate.ExecuteFind<UserQuery>(delegate(ISession session) 
            {
//                return SqlMapper.Query<UserQuery>(session.Connection,
//@"select u.UserName, u.Email, u.State, 
//c.UserName CreatorName, c.Email CreatorEmail, c.State CreatorState,
//c.UserName CreatorName1, c.Email CreatorEmail1, c.State CreatorState1,
//c.UserName CreatorName2, c.Email CreatorEmail2, c.State CreatorState2,
//c.UserName CreatorName3, c.Email CreatorEmail3, c.State CreatorState3  
//from Users u inner join Users c on u.CreatorId = c.Id").ToList();

                IDbCommand cmd = session.Connection.CreateCommand();
                cmd.CommandText = @"select u.UserName, u.Email, u.State, 
c.UserName CreatorName, c.Email CreatorEmail, c.State CreatorState,
c.UserName CreatorName1, c.Email CreatorEmail1, c.State CreatorState1,
c.UserName CreatorName2, c.Email CreatorEmail2, c.State CreatorState2,
c.UserName CreatorName3, c.Email CreatorEmail3, c.State CreatorState3  
from Users u inner join Users c on u.CreatorId = c.Id";

                IDataReader reader = cmd.ExecuteReader();
                reader.Close();

                return null;
            });

        }
    }
}
